package com.xunfang.demo.service;

import com.xunfang.demo.dao.UserDao;
import com.xunfang.demo.dao.UserDaoImpl;
import com.xunfang.demo.entity.QueryData;
import com.xunfang.demo.entity.UserDemo;
import com.xunfang.demo.utils.PageBean;

import java.util.List;

public class UserServiceImpl implements UserService {

    UserDao userDao = new UserDaoImpl();

    @Override
    public PageBean getUserByPB(QueryData queryData, Integer p) {
        PageBean pb = new PageBean();
        pb.setPageSize(5);
        int userbyBD = userDao.findUserbyBD(queryData);
        pb.setPageTotal(userbyBD);
        pb.setP(p);
        List<UserDemo> list = userDao.findUserBySome(queryData, pb.getP(), pb.getPageSize());
        pb.setDataList(list);
        return pb;
    }

    @Override
    public boolean addUser(UserDemo userDemo) {
        return userDao.insertUser(userDemo) > 0 ? true : false;
    }

    @Override
    public boolean existsUsers(String username, String userpwd) {
        return userDao.selectBySome(username,userpwd)!=null ? true: false;
    }

    @Override
    public List<UserDemo> findUserAll() {
        return userDao.selectUserAll();
    }

    @Override
    public boolean removeUserById(Integer id) {
        return userDao.delUserById(id) > 0 ? true : false;
    }

    @Override
    public UserDemo findUserById(int id) {
        return userDao.selectByid(id);
    }

    @Override
    public boolean updateById(UserDemo userDemo) {
        return userDao.updateById(userDemo) > 0;
    }

    @Override
    public List<UserDemo> getUserBySome(QueryData queryData) {
        return userDao.getUserBySome(queryData);
    }

    @Override
    public boolean findUserName(String name) {
        return userDao.selectUserName(name)!=null ? true: false;
    }
}
